﻿/*************************************************************************
*  Copyright (C), 2016-2017, Mogoson tech. Co., Ltd.
*  FileName: CREditor.cs
*  Author: Mogoson   Version: 1.0   Date: 9/1/2016
*  Version Description:
*    Internal develop version,mainly to achieve its function.
*  File Description:
*    Ignore.
*  Class List:
*    <ID>           <name>             <description>
*     1.           CREditor               Ignore.
*  Function List:
*    <class ID>     <name>             <description>
*     1.
*  History:
*    <ID>    <author>      <time>      <version>      <description>
*     1.     Mogoson     9/1/2016       1.0        Build this file.
*************************************************************************/

namespace Developer.CRTool
{
    using UnityEditor;
    using UnityEngine;

    /// <summary>

    /// Cubemap Render Editor.

    /// </summary>

    public class CREditor : ScriptableWizard
    {
        #region Property and Field
        [Tooltip("Target render camera.")]
        public Camera renderCamera;
        #endregion

        #region Private Method
        [MenuItem("Tool/CREditor &C")]
        static void ShowCREditor()
        {
            DisplayWizard("CREditor", typeof(CREditor), "Render");
        }//Show...()_end


        //Window update.

        void OnWizardUpdate()
        {
            if (renderCamera)
                isValid = true;
            else
                isValid = false;
        }//OnW...()_end


        //Render button click.

        void OnWizardCreate()
        {
            //Create newRenderCubemap and render camera to it.

            var newRenderCubemap = new Cubemap(64, TextureFormat.ARGB32, false);
            renderCamera.RenderToCubemap(newRenderCubemap);

            //Select save path.

            var newCubemapPath = EditorUtility.SaveFilePanelInProject("Save New Render Cubemap", "NewRenderCubemap", "cubemap",
                "Enter a file name to save the new render cubemap.");
            if (newCubemapPath == string.Empty)
                return;

            //Save newRenderCubemap to AssetDatabase.

            AssetDatabase.CreateAsset(newRenderCubemap, newCubemapPath);
            AssetDatabase.Refresh();
        }//OnW...()_end

        #endregion
    }//class_end

}//namespace_end